import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

Dio dio = Dio();

class Namesc extends StatefulWidget {
  Namesc({Key key}) : super(key: key);

  @override
  _NamescState createState() => _NamescState();
}

class _NamescState extends State<Namesc> {
  void initState() {
    super.initState();
    this.getlist();
  }

  List limst = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: new Text('北美票房'),
          backgroundColor: Colors.blue,
          centerTitle: true,
        ),
        body: this.limst.length == 0
            ? Text('加载中...')
            : Padding(
                padding: EdgeInsets.all(8.0),
                child: ListView(
                  children: <Widget>[
                    ...this.limst.map((item) {
                      return GestureDetector(
                          onTap: () {
                            print(item['id']);
                            Navigator.pushNamed(context, '/detail', arguments: {
                              'id': item['subject']['id'],
                              'title': item['title']
                            });
                          },
                          child: Container(
                            // decoration: ,
                            
                            color: Colors.black12,
                            margin: EdgeInsets.only(bottom: 10),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Container(
                                    width: 150,
                                    
                                    margin: EdgeInsets.only(right: 10),
                                    child: Image.network(
                                      item['subject']['images']['small'],
                                      fit: BoxFit.cover,
                                    )),
                                Expanded(
                                    child: Container(
                                  alignment: Alignment.topLeft,
                                  height: 220,
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceAround,
                                    children: <Widget>[
                                      Container(
                                          child: Text(
                                        '电影 : ${item['subject']['title']}',
                                        style: TextStyle(
                                          fontSize: 20.0,
                                        ),
                                      )),
                                      Text(
                                        '上映年份 : ${item['subject']['pubdates'][0]}',
                                        style: TextStyle(fontSize: 13,color: Colors.black54),
                                      ),
                                      Text(
                                          '电影类型 : ${item['subject']['genres'].join('  ')}'),
                                      Text(
                                          '电影评分 ：${item['subject']['rating']['average']} 分'),
                                      Container(
                                        child: Row(
                                          children: <Widget>[
                                            Text('演员列表: '),
                                            ...item['subject']['casts']
                                                .map((item) {
                                              return Container(
                                                  margin:
                                                      EdgeInsets.only(left: 5),
                                                  child: ClipOval(
                                                    child: Image.network(
                                                      item['avatars']['small'],
                                                      fit: BoxFit.cover,
                                                      width: 30,
                                                      height: 30,
                                                    ),
                                                  ));
                                            })
                                          ],
                                        ),
                                      )
                                    ],
                                  ),
                                ))
                              ],
                            ),
                          ));
                    })
                  ],
                ),
              ));
  }

  getlist() async {
    print(this.limst.length);
    var response = await dio.get('https://douban.uieee.com/v2/movie/us_box');
    print(response.data['subjects'] is List);
    this.setState(() {
      this.limst = response.data['subjects'];
    });
  }
}
